package ru.papergames.battleserver.network.clientpackets.webserver;

import org.apache.log4j.Logger;
import ru.papergames.battleserver.model.WebServerClientHolder;
import ru.papergames.battleserver.network.WebServerClient;
import ru.papergames.battleserver.network.serverpackets.webserver.WebServerAuthPassed;

/**
 * @author: ATroshanin
 * Date: 19.04.2010
 * Time: 13:21:41
 */
public class AuthorizeWebServer extends WebServerClientPacket{

    private static final Logger log = Logger.getLogger(AuthorizeWebServer.class.getName());

    private int webServerId;

    @Override
    protected void readImpl() {
        webServerId = readD();
    }

    @Override
    protected void runImpl() {
        log.info("web-server[" + webServerId + "] is authorized");
        getClient().setState(WebServerClient.WebServerClientState.AUTHORIZED);
        getClient().sendPacket(WebServerAuthPassed.STATIC_PACKET);

        WebServerClientHolder.getInstance().setWebServerClient(getClient());
        WebServerClientHolder.getInstance().setWebServerClientBeforeAuth(null);
    }

    @Override
    public String getType() {
        return "[c] AuthorizeWebServer[" + AUTHORIZE_WEB_SERVER_PACKET_ID + "]";
    }
}
